import json

src_dir = '/home/guoyi/Dataset'
tgt_dir = '/home/zhangpinglu/data0/gy/Dataset'

# 读取你的文件列表
json_files = [
    './experiments/aier_colde_start_data/aier_cold_start_test.json',
    './experiments/aier_colde_start_data/aier_cold_start_train.json'
    ]

for json_file in json_files:
    print(f'Processing: {json_file}')
    # 读取原始json
    with open(json_file, 'r', encoding='utf-8') as f:
        data = json.load(f)
    modified = False

    # 替换路径
    for item in data:
        if "images" in item and isinstance(item["images"], list):
            new_images = []
            for img_path in item["images"]:
                if isinstance(img_path, str) and src_dir in img_path:
                    new_path = img_path.replace(src_dir, tgt_dir)
                    if new_path != img_path:
                        modified = True
                    new_images.append(new_path)
                else:
                    new_images.append(img_path)
            item["images"] = new_images

    # 写回原文件（只在有修改时覆盖）
    if modified:
        with open(json_file, 'w', encoding='utf-8') as f:
            json.dump(data, f, ensure_ascii=False, indent=2)
        print(f'Updated: {json_file}')
    else:
        print(f'No changes in: {json_file}')
